﻿using AiBLSmartEdu.Module.SmartPhysics.API.DTOs;
using AiBLSmartEdu.Module.SmartPhysics.API.Services;
using Domain;
using FrameworkCore;
using FrameworkCore.Controllers;
using FrameworkCore.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AiBLSmartEdu.Module.SmartPhysics.API.Controllers;

/// <summary>
/// 物理智能问答助手服务
/// </summary>
[AllowAnonymous]
public class SmartPhysicsController : BaseModuleController
{
    private readonly PhysicsQuestionServices _physicsQuestionServices;

    public SmartPhysicsController(PhysicsQuestionServices physicsQuestionServices)
    {
        _physicsQuestionServices = physicsQuestionServices;
    }

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="filter">分页输入模型</param>
    /// <returns></returns>
    [HttpGet("Page")]
    public async Task<PageResult<PhysicsQuestionOutputModel>> PaginationAsync([FromQuery] PhysicsQuestionPaginationFilter filter)
    {
        return await _physicsQuestionServices.PageAsync(filter);
    }

    /// <summary>
    /// 创建问题
    /// </summary>
    /// <param name="input">输入模型</param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Result> CreateAsync(PhysicsQuestionCreateInputModel input)
    {
        await _physicsQuestionServices.CreateAsync(input);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 修改状态
    /// </summary>
    /// <param name="id">唯一标识</param>
    /// <param name="status">状态</param>
    /// <returns></returns>
    [HttpPut("{id}/{status}")]
    public async Task<Result> UpdateAsync(long id, PhysicsQuestionStatus status)
    {
        await _physicsQuestionServices.UpdateStatusAsync(id, status);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 是否收藏
    /// </summary>
    /// <param name="id">唯一标识</param>
    /// <returns></returns>
    [HttpPut("Favorited/{id}")]
    public async Task<Result> IsFavoritedAsync(long id)
    {
        await _physicsQuestionServices.IsFavoritedAsync(id);
        return await Result.SucceedAsync();
    }

    /// <summary>
    /// 查询答案
    /// </summary>
    /// <param name="id">唯一标识</param>
    /// <returns></returns>
    [HttpGet("Query/Answer/{id}")]
    public async Task<Result<string>> QueryAnswerAsync(long id)
    {       
        return await Result<string>.SucceedAsync(await _physicsQuestionServices.QueryAnswerAsync(id));
    }

    /// <summary>
    /// 批量删除
    /// </summary>
    /// <returns></returns>
    [HttpDelete("{ids}")]
    public async Task<Result> BulkDeletesAsync(string ids)
    {
        await _physicsQuestionServices.DeleteAsync(ids);
        return await Result.SucceedAsync();
    }
}
